<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>添加账号</title>
	<link rel="stylesheet" href="../css/layui.css">
<link rel="stylesheet" href="/scriptZIP/layui.min.css">
	<link rel="stylesheet" href="../css/check_box.css">
	<link rel="stylesheet" href="../css/radio.css">
	<link rel="stylesheet" href="../css/item.css">
	<style>
		.checkbox-inline {
			width: calc(100% / 4.5);
		}

		.i-checks input:checked+i:before {
			top: 1px;
			left: 1px;
			width: 8px;
			height: 8px;
		}

		.i-checks>i {
			width: 12px;
			height: 12px;
		}

		.offer {
			width: 130px;
			height: 40px;
			background: #0086b6;
			color: white;
			text-align: center;
			line-height: 40px;
			font-size: 16px;
		}

		.return {
			width: 130px;
			height: 40px;
			background: #0086b6;
			color: white;
			text-align: center;
			line-height: 40px;
			margin-top: -40px;
			margin-left: 180px;
			font-size: 16px;
		}

		.labels {
			width: 70%;
			min-width: 600px;
			margin-top: -20px;
			margin-left: 110px;
		}

		.label {
			margin-top: 0;
		}

		.layui-input-block.true {
			padding-top: 13px;
			line-height: 15px;
		}

		.layui-input-block.true>input:not(:first-child) {
			margin-left: 20px;
		}

		[v-show],
		[v-if] {
			display: none;
		}
	</style>
</head>

<body>

	<div class="layui-row" id="vue-root">
		<div></div>
		<div class="layui-col-md6 layui-col-md-offset3">
			<div class="layui-form-item">
				<label class="layui-form-label">账号</label>
				<div class="layui-input-block">
					<input name="deviceName" autocomplete="off" placeholder="请输入账号" class="layui-input"
						v-model="item1.username" style="width: 50%">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">密码</label>
				<div class="layui-input-block">
					<input name="deviceName" type="password" autocomplete="off" placeholder="请输入密码" class="layui-input"
						v-model="item1.password" style="width: 50%">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">权限</label>
				<div class="layui-input-block">
					<select name="authName" data-vv-as="权限" class="input_select classteacher "
						v-model="item1.authorityId">
						<option :value="undefined" disabled="disabled">请选择权限</option>
						<option v-for="auth in auths" :key="auth.id" :value="auth.id" v-text="auth.name">
						</option>
					</select>
					<div class="checkout_state" v-text="err('authName')"></div>
					</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">教师</label>
				<div class="layui-input-block">
					<select name="authName" data-vv-as="教师" class="input_select classteacher "
						v-model="item1.teacherId">
						<option :value="undefined" disabled="disabled">请选择教师</option>
						<option v-for="teacher in teachers" :key="teacher.id" :value="teacher.id" v-text="teacher.name">
						</option>
					</select>
					<div class="checkout_state" v-text="err('teacherName')"></div>
					</div>
			</div>


			<div class="layui-form-item">
				<div class="layui-input-block">
					<div class="offer" @click="submit">立即提交</div>
					<div class="return" onclick="history.back()">取消</div>
				</div>
			</div>
		</div>

	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/item.js"></script>
	<script src="/js/auth_util.js"></script>
	<script src="/js/menu.js"></script>


	<script>
		new Vue(merge({
			data: {
				item1: {
					username: '',
					password: '',
					authorityId:'',
					teacherId:''
					
				},
				list: list,
				parent: {},
				auths:[],
				teachers:[],
				url: '/pc/user'
			},
			created: function () {
				axios.get('/pc/user/school/' + top_params().id).then(function (res) {
					console.log(res);
					this.init();
				}.bind(this));
				axios.get('/pc/auth/all/' + top_params().id).then(function (res) {
					this.auths = res.data;
				}.bind(this));
				axios.get('/pc/teacher/all/' + top_params().id).then(function (res) {
					this.teachers = res.data;
				}.bind(this));
			},
			methods: {
				// doAll: function (o) {
				// 	o.list.forEach(function (it) {
				// 		it.allows = [o.all, o.all, o.all, o.all];
				// 	});
				// },
				// some: function (it) {
				// 	return it && it.some(function (i) {
				// 		return i;
				// 	});
				// },
				// some1: function (it) {
				// 	return it.list.some(function (it1) {
				// 		return this.some(this.parent[it1.key]);
				// 	}.bind(this));
				// },
				formatData: function (data) {
					// var a = data.authority;
					// delete data.authority;
					this.item1 = data;
					// this.list.forEach(function (it1) {
					// 	it1.list.forEach(function (it) {
					// 		it.allows = f(a[it.key]);
					// 	});
					// });
				},
				submit: function () {
					
					this.item = this.item1;
					if (this.item.id) {
						axios.put('/pc/user', this.item).then(function (res) {
							alert('成功');
							history.back();
						});
					} else {
						this.item.relatedId = top_params().id;
						axios.post('/pc/user/school', this.item).then(function (res) {
							alert('添加成功');
							history.back();
						});
					}

				}
			}
		}));
	</script>


</body>

</html>